package com.mulanweb.utils;

import java.util.*;

/**
 * Created by Administrator on 2016/8/31.
 */
public class SortUtil {

    /**
     * 升序排列
     * @param map
     * @return
     */
    public static Map mapSortRise(Map<String,String> map){
        Map<String,Object> result = new TreeMap<String,Object>();
        Set<String> keySet = map.keySet();
        Iterator<String> iter = keySet.iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            result.put(key,map.get(key));
        }
        return result ;
    }

    /**
     * 降序排列
     * @param map
     * @return
     */
    public static Map mapSortDesc(Map<String,String> map){
        Map<String, Object> result= new TreeMap<String, Object>(
                new Comparator<String>() {
                    public int compare(String obj1, String obj2) {
                        // 降序排序
                        return obj2.compareTo(obj1);
                    }
                });
        Set<String> keySet = map.keySet();
        Iterator<String> iter = keySet.iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            result.put(key,map.get(key));
        }
        return result ;
    }
}
